//
//  GMBuyVideoVC.m
//  Teecloud
//
//  Created by 小熊 on 2018/10/25.
//  Copyright © 2018年 小志. All rights reserved.
//

#import "GMBuyVideoVC.h"
#import "GMCommentBaseModel.h"
#import "GMRemarksModel.h"
/**头视图*/
#import "GMBuyWebView.h"
#import "GMBuyKnowCell.h"
#import "GMBuyMoneyCell.h"
#import "GMComentCountCell.h"
/**cell视图*/
#import "GMBuyKnowlegeCell.h"
#import "GMCommentCell.h"
#import "ZFAVPlayerManager.h"
#import "ZFPlayerControlView.h"
#import "ZFPlayer.h"
#import <WebKit/WebKit.h>

#import "GMVoiceListModel.h"
#import "GMPopComentVC.h"
@interface GMBuyVideoVC ()<UITableViewDataSource,UITableViewDelegate,WKUIDelegate, WKNavigationDelegate>

@property (weak, nonatomic) IBOutlet UITableView *tabView;
@property(nonatomic, strong) NSMutableArray *cellArr;
@property(nonatomic, strong) GMCommentBaseModel *baseModel;
@property (weak, nonatomic) IBOutlet UIView *fatherView;
@property (nonatomic ,strong) ZFPlayerView  *playerView;
/** 离开页面时候是否在播放 */
@property (nonatomic, assign) BOOL isPlaying;
/**用来装网页视图*/
@property (nonatomic, strong) UIScrollView *scrollView;
@property (nonatomic, strong) WKWebView *webView;
/**网页高度*/
@property (nonatomic, assign) CGFloat webViewHeight;

@property (nonatomic, strong) ZFPlayerController *player;
@property (nonatomic, strong) ZFPlayerControlView *controlView;
@property (nonatomic, strong) UIBarButtonItem *colectItem;
@property (nonatomic, strong) UIBarButtonItem *shareItem;
@property (nonatomic, strong) UIButton *colectBtn;

/**:1 点赞，2 取消点赞*/
@property (nonatomic, copy) NSString *op;
/**:1 收藏，2 取消收藏*/
@property (nonatomic, strong) NSNumber *type;

@end

@implementation GMBuyVideoVC
- (void)viewWillAppear:(BOOL)animated {
    [super viewWillAppear:animated];
    self.player.viewControllerDisappear = NO;
}

- (void)viewWillDisappear:(BOOL)animated {
    [super viewWillDisappear:animated];
    self.player.viewControllerDisappear = YES;
}
- (void)viewDidLoad {
    [super viewDidLoad];
    [self getBuyVideoData];
    self.webViewHeight = 0.0;
    self.scrollView = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, 1)];
    [self.scrollView addSubview:self.webView];
    /**注册组头*/
    [self.tabView registerNib:[UINib nibWithNibName:@"GMBuyMoneyCell" bundle:nil] forHeaderFooterViewReuseIdentifier:@"GMBuyMoneyCell"];
    [self.tabView registerNib:[UINib nibWithNibName:@"GMBuyWebView" bundle:nil] forHeaderFooterViewReuseIdentifier:@"GMBuyWebView"];
    [self.tabView registerNib:[UINib nibWithNibName:@"GMBuyKnowCell" bundle:nil] forHeaderFooterViewReuseIdentifier:@"GMBuyKnowCell"];
    [self.tabView registerNib:[UINib nibWithNibName:@"GMComentCountCell" bundle:nil] forHeaderFooterViewReuseIdentifier:@"GMComentCountCell"];
    /**注册cell*/
    [self.tabView registerClass:[UITableViewCell class] forCellReuseIdentifier:@"webCell"];
    [self.tabView registerNib:[UINib nibWithNibName:@"GMBuyKnowlegeCell" bundle:nil] forCellReuseIdentifier:@"GMBuyKnowlegeCell"];
    [self.tabView registerNib:[UINib nibWithNibName:@"GMCommentCell" bundle:nil] forCellReuseIdentifier:@"GMCommentCell"];
      [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(getBuyVideoData) name:@"updataContent" object:nil];
    
    _colectBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    [_colectBtn addTarget:self action:@selector(colectBtnClcik) forControlEvents:UIControlEventTouchUpInside];
    [_colectBtn setImage:[UIImage imageNamed:@"uncolected"] forState:UIControlStateNormal];
    [_colectBtn setImage:[UIImage imageNamed:@"colected"] forState:UIControlStateSelected];
    [_colectBtn sizeToFit];
    _colectItem = [[UIBarButtonItem alloc] initWithCustomView:_colectBtn];
    UIButton *shareBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    [shareBtn addTarget:self action:@selector(shareBtnClick) forControlEvents:UIControlEventTouchUpInside];
    [shareBtn setImage:[UIImage imageNamed:@"share_white"] forState:UIControlStateNormal];
    [shareBtn sizeToFit];
    _shareItem = [[UIBarButtonItem alloc] initWithCustomView:shareBtn];
    self.navigationItem.rightBarButtonItems  = @[self.shareItem,self.colectItem];
    [self addLeftBarButtonWithImage:[UIImage imageNamed:@"left-white-64"] action:@selector(left_BarButtonItemAction)];
}
- (void)left_BarButtonItemAction {
    if (kIsEmptyString(self.typeStr)) {
        [self.navigationController popViewControllerAnimated:YES];
    }else{
        [self.navigationController popToRootViewControllerAnimated:YES];
    }
}
- (void)getBuyVideoData{
    NSMutableDictionary *dict = [NSMutableDictionary dictionary];
    [dict setValue:FROM_IOS forKey:@"from"];
    [dict setValue:[XGMArchiverTools cacheForKey:BUSIORGID] forKey:@"busiOrgId"];
    [dict setValue:[XGMArchiverTools cacheForKey:USER_UserId] forKey:@"userId"];
    [dict setValue:[XGMArchiverTools cacheForKey:USER_identifierNumber] forKey:@"loginFinger"];
    [dict setValue:self.resId forKey:@"resId"];
    [dict setValue:self.packId forKey:@"packId"];
    [MBProgressHUD showHUDAddedTo:self.view animated:YES];
    [HJNetwork HTTPWithMethod:HJRequestMethodPOST url:[NSString stringWithFormat:@"ajax-api.ashx?$c=TeeyunApp&$m=GetTryResData&$v=%@",VERSION] parameters:dict cachePolicy:HJCachePolicyIgnoreCache callback:^(id responseObject, NSError *error) {
        [MBProgressHUD hideHUDForView:self.view animated:YES];
        if (!error) {
            if ([[responseObject objectForKey:RESULT_NAME_Success] boolValue]) {
                GMCommentBaseModel *comModel = [GMCommentBaseModel mj_objectWithKeyValues:[responseObject objectForKey:RESULT_NAME_Data]];
                comModel.ResType = self.ResType;
                self.title = comModel.Name;
                self.baseModel = comModel;
                if (comModel.IsCollect) {
                    self.colectBtn.selected = YES;
                    self.type = @(2);
                }else{
                    self.colectBtn.selected = NO;
                    self.type = @(1);
                }
                ZFAVPlayerManager *playerManager = [[ZFAVPlayerManager alloc] init];
                /// 播放器相关
                self.player = [ZFPlayerController playerWithPlayerManager:playerManager containerView:self.fatherView];
                self.player.controlView = self.controlView;
               
                [self.controlView showTitle:comModel.Name coverURLString:comModel.HeadUrl fullScreenMode:ZFFullScreenModeLandscape];
                /// 设置退到后台继续播放
                self.player.pauseWhenAppResignActive = NO;
                kWeakObject(self)
                self.player.orientationWillChange = ^(ZFPlayerController * _Nonnull player, BOOL isFullScreen) {
                    
                    [weakself setNeedsStatusBarAppearanceUpdate];
                };
                /// 播放完成
                self.player.playerDidToEnd = ^(id  _Nonnull asset) {
                    [weakself.player.currentPlayerManager replay];
                };
                
                self.player.playerReadyToPlay = ^(id<ZFPlayerMediaPlayback>  _Nonnull asset, NSURL * _Nonnull assetURL) {
                    NSLog(@"======开始播放了");
                };
                self.player.playerPlayTimeChanged = ^(id<ZFPlayerMediaPlayback>  _Nonnull asset, NSTimeInterval currentTime, NSTimeInterval duration) {
                    NSLog(@"%f",currentTime);
                    NSInteger tepTime =round(currentTime);
                    if ([comModel.TryPlayTimeLen integerValue] <=tepTime) {
                            //暂停播放
                        [weakself.player.currentPlayerManager pause];
                        UIAlertController *alert = [UIAlertController zj_alertControllerWithTitle:@"" message:@"试播结束" optionStyle:OptionStyleStyleOnlyOK OkTitle:@"确定" cancelTitle:@"" okBlock:^{
                            
                        } cancelBlock:^{
                            
                        }];
//                        UIAlertController *alert = [UIAlertController zj_alertControllerWithTitle:@"" message:@"试播结束，点击【立即购买】购买本课程资源" optionStyle:OptionStyleStyleOK_Cancel OkTitle:@"立即购买" cancelTitle:@"取消" okBlock:^{
//
//                        } cancelBlock:^{
//
//                        }];
                        [weakself presentViewController:alert animated:YES completion:nil];
                    }
                };
                self.player.assetURL =[NSURL URLWithString:comModel.Url];
                NSArray *temArr;
                if (!kIsEmptyString(comModel.Memo)) {
                    [self.webView loadHTMLString:comModel.Memo baseURL:nil];
                }
                if ([self.ResType isEqualToNumber:@(3)] ||[self.ResType isEqualToNumber:@(4)]) {
                    temArr = @[@"GMBuyMoneyCell",@"GMBuyWebView",@"GMComentCountCell"];
                }else{
                    temArr = @[@"GMBuyMoneyCell",@"GMBuyWebView",@"GMBuyKnowCell",@"GMComentCountCell"];
                }
                [self.cellArr removeAllObjects];
                [self.cellArr addObjectsFromArray:temArr];
                [self.tabView reloadData];
            }
        }else{
            [MBProgressHUD showErrorOrSuc:@"请求出错" toView:self.view];
        }
    }];
}
- (ZFPlayerControlView *)controlView {
    if (!_controlView) {
        _controlView = [ZFPlayerControlView new];
        _controlView.fastViewAnimated = YES;
        _controlView.bottomPgrogress.allowTapped = NO;
    }
    return _controlView;
}

-(WKWebView *)webView{
    if (!_webView) {
        WKWebViewConfiguration *wkWebConfig = [[WKWebViewConfiguration alloc] init];
        WKUserContentController *wkUController = [[WKUserContentController alloc] init];
        wkWebConfig.userContentController = wkUController;
        // 自适应屏幕宽度js
        NSString *jSString = @"var meta = document.createElement('meta'); meta.setAttribute('name', 'viewport'); meta.setAttribute('content', 'width=device-width'); document.getElementsByTagName('head')[0].appendChild(meta);";
        WKUserScript *wkUserScript = [[WKUserScript alloc] initWithSource:jSString injectionTime:WKUserScriptInjectionTimeAtDocumentEnd forMainFrameOnly:YES];
        // 添加js调用
        [wkUController addUserScript:wkUserScript];
        
        _webView = [[WKWebView alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, 1) configuration:wkWebConfig];
        _webView.backgroundColor = [UIColor clearColor];
        _webView.opaque = NO;
        _webView.userInteractionEnabled = NO;
        _webView.scrollView.bounces = NO;
        _webView.UIDelegate = self;
        _webView.navigationDelegate = self;
        [_webView sizeToFit];
        [_webView.scrollView addObserver:self forKeyPath:@"contentSize" options:NSKeyValueObservingOptionNew context:nil];
    }
    return _webView;
}
- (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary<NSString *,id> *)change context:(void *)context
{
    if ([keyPath isEqualToString:@"contentSize"]) {
        // 方法一
        UIScrollView *scrollView = (UIScrollView *)object;
        CGFloat height = scrollView.contentSize.height;
        self.webViewHeight = height;
        self.webView.frame = CGRectMake(0, 0, self.view.frame.size.width, height);
        self.scrollView.frame = CGRectMake(0, 0, self.view.frame.size.width, height);
        self.scrollView.contentSize =CGSizeMake(self.view.frame.size.width, height);
        if (!kIsEmptyString(self.baseModel.Memo)){//有数据在刷新
            [self.tabView reloadRowsAtIndexPaths:[NSArray arrayWithObjects:[NSIndexPath indexPathForRow:0 inSection:1], nil] withRowAnimation:UITableViewRowAnimationNone];
        }
        /*
         // 方法二
         [_webView evaluateJavaScript:@"document.body.offsetHeight" completionHandler:^(id _Nullable result, NSError * _Nullable error) {
         CGFloat height = [result doubleValue] + 20;
         self.webViewHeight = height;
         self.webView.frame = CGRectMake(0, 0, self.view.frame.size.width, height);
         self.scrollView.frame = CGRectMake(0, 0, self.view.frame.size.width, height);
         self.scrollView.contentSize =CGSizeMake(self.view.frame.size.width, height);
         [self.tableView reloadRowsAtIndexPaths:[NSArray arrayWithObjects:[NSIndexPath indexPathForRow:3 inSection:0], nil] withRowAnimation:UITableViewRowAnimationNone];
         }];
         */
    }
}

-(UITableView *)tabView{
    if (!_tabView) {
        _tabView = [UITableView zj_tableViewWithSuperview:self.view delegate:self style:UITableViewStylePlain constraints:^(MASConstraintMaker *make) {
            make.edges.equalTo(self.view);
        }];
        /**注册组头*/
        _tabView.separatorStyle = UITableViewCellAccessoryNone;
        [_tabView registerNib:[UINib nibWithNibName:@"GMBuyMoneyCell" bundle:nil] forHeaderFooterViewReuseIdentifier:@"GMBuyMoneyCell"];
        [_tabView registerNib:[UINib nibWithNibName:@"GMBuyWebView" bundle:nil] forHeaderFooterViewReuseIdentifier:@"GMBuyWebView"];
        [_tabView registerNib:[UINib nibWithNibName:@"GMBuyKnowCell" bundle:nil] forHeaderFooterViewReuseIdentifier:@"GMBuyKnowCell"];
        [_tabView registerNib:[UINib nibWithNibName:@"GMComentCountCell" bundle:nil] forHeaderFooterViewReuseIdentifier:@"GMComentCountCell"];
        /**注册cell*/
        [_tabView registerClass:[UITableViewCell class] forCellReuseIdentifier:@"webCell"];
        [_tabView registerNib:[UINib nibWithNibName:@"GMBuyKnowlegeCell" bundle:nil] forCellReuseIdentifier:@"GMBuyKnowlegeCell"];
        [_tabView registerNib:[UINib nibWithNibName:@"GMCommentCell" bundle:nil] forCellReuseIdentifier:@"GMCommentCell"];
        
    }
    return _tabView;
}
- (void)getBuyFileData{
    NSDictionary *dict= @{@"from":FROM_IOS,
                          @"busiOrgId":[XGMArchiverTools cacheForKey:BUSIORGID],
                          @"loginFinger":[XGMArchiverTools cacheForKey:USER_identifierNumber],
                          @"userId":[XGMArchiverTools cacheForKey:USER_UserId],
                          @"resId":self.resId
                          };
    [MBProgressHUD showHUDAddedTo:self.view animated:YES];
    [HJNetwork HTTPWithMethod:HJRequestMethodPOST url:[NSString stringWithFormat:@"ajax-api.ashx?$c=TeeyunApp&$m=GetTryResData&$v=%@",VERSION] parameters:dict cachePolicy:HJCachePolicyIgnoreCache callback:^(id responseObject, NSError *error) {
        [MBProgressHUD hideHUDForView:self.view animated:YES];
        if (!error) {
            if ([[responseObject objectForKey:RESULT_NAME_Success] boolValue]) {
                GMCommentBaseModel *comModel = [GMCommentBaseModel mj_objectWithKeyValues:[responseObject objectForKey:RESULT_NAME_Data]];
                comModel.ResType = self.ResType;
                self.baseModel = comModel;
                NSArray *temArr;
                if (!kIsEmptyString(comModel.Memo)) {
                    [self.webView loadHTMLString:comModel.Memo baseURL:nil];
                }
                if ([self.ResType isEqualToNumber:@(3)] ||[self.ResType isEqualToNumber:@(4)]) {
                    temArr = @[@"GMBuyMoneyCell",@"GMBuyWebView",@"GMComentCountCell"];
                }else{
                    temArr = @[@"GMBuyMoneyCell",@"GMBuyWebView",@"GMBuyKnowCell",@"GMComentCountCell"];
                }
                [self.cellArr removeAllObjects];
                [self.cellArr addObjectsFromArray:temArr];
                [self.tabView reloadData];
            }
        }else{
            [MBProgressHUD showErrorOrSuc:@"请求出错" toView:self.view];
        }
    }];
}
-(NSMutableArray *)cellArr{
    if (!_cellArr) {
        _cellArr = [[NSMutableArray alloc]init];
    }
    return _cellArr;
}
- (nullable UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section{
    NSString *cellIDStr =self.cellArr[section];
    if ([cellIDStr isEqualToString:@"GMBuyMoneyCell"]) {
        GMBuyMoneyCell *cell = [tableView dequeueReusableHeaderFooterViewWithIdentifier:cellIDStr];
        if (!kIsEmptyString(self.packName)) {
            self.baseModel.tempStr = self.packName;
        }
        cell.model = self.baseModel;
        return cell;
    }else if ([cellIDStr isEqualToString:@"GMBuyWebView"]){
        GMBuyWebView *cell = [tableView dequeueReusableHeaderFooterViewWithIdentifier:cellIDStr];
        cell.model = self.baseModel;
        return cell;
    }else if ([cellIDStr isEqualToString:@"GMBuyKnowCell"]){
        GMBuyKnowCell *cell = [tableView dequeueReusableHeaderFooterViewWithIdentifier:cellIDStr];
        cell.model = self.baseModel;
        kWeakObject(self)
        cell.block = ^{
            if (weakself.baseModel.isopen) {
                weakself.baseModel.isopen =NO;
            }else{
                weakself.baseModel.isopen =YES;
            }
            [self.tabView reloadData];
        };
        return cell;
    }else{
        GMComentCountCell *cell = [tableView dequeueReusableHeaderFooterViewWithIdentifier:cellIDStr];
        return cell;
    }
}
- (nullable UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section{
    UIView *bagView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, DEVICE_WIDTH, 5)];
    bagView.backgroundColor =kRGB(245, 245, 245);
    return bagView;
}
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
    NSString *cellIDStr =self.cellArr[section];
    if ([cellIDStr isEqualToString:@"GMBuyMoneyCell"]) {
        return 60;
    }else if ([cellIDStr isEqualToString:@"GMBuyWebView"]){
        return 60;
    }else if ([cellIDStr isEqualToString:@"GMBuyKnowCell"]){
        return 50;
    }else{
        return 50;
    }
}
- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section{
    return 5.0;
}
- (nonnull UITableViewCell *)tableView:(nonnull UITableView *)tableView cellForRowAtIndexPath:(nonnull NSIndexPath *)indexPath {
    NSString *cellIDStr =self.cellArr[indexPath.section];
    if ([cellIDStr isEqualToString:@"GMBuyMoneyCell"]) {
        return 0;
    }else if ([cellIDStr isEqualToString:@"GMBuyWebView"]){
        if (kIsEmptyString(self.baseModel.Memo)) {
            //如果没有富文本就不加载cell
            return 0;
        }else{
            UITableViewCell *webCell = [tableView dequeueReusableCellWithIdentifier:@"webCell" forIndexPath:indexPath];
            [webCell.contentView addSubview:self.scrollView];
            return webCell;
        }
    }else if ([cellIDStr isEqualToString:@"GMBuyKnowCell"]){
        GMBuyKnowlegeCell *cell = [tableView dequeueReusableCellWithIdentifier:@"GMBuyKnowlegeCell" forIndexPath:indexPath];
        cell.moedl = self.baseModel.Dirs[indexPath.row];
        return cell;
    }else{
        GMCommentCell *cell =[tableView dequeueReusableCellWithIdentifier:@"GMCommentCell" forIndexPath:indexPath];
        GMRemarksModel *model = self.baseModel.Remarks[indexPath.row];
        cell.reModel = model;
        kWeakObject(self)
        cell.likeBlock = ^{
            if (model.IsLike) {
                weakself.op = @"2";
            }else{
                weakself.op = @"1";
            }
            NSDictionary *dict= @{@"from":FROM_IOS,
                                  @"busiOrgId":[XGMArchiverTools cacheForKey:BUSIORGID],
                                  @"loginFinger":[XGMArchiverTools cacheForKey:USER_identifierNumber],
                                  @"userId":[XGMArchiverTools cacheForKey:USER_UserId],
                                  @"recId":model.Id,
                                  @"type":@(1),
                                  @"op":self.op
                                  };
            [MBProgressHUD showHUDAddedTo:weakself.view animated:YES];
            [HJNetwork HTTPWithMethod:HJRequestMethodPOST url:[NSString stringWithFormat:@"ajax-api.ashx?$c=TeeyunApp&$m=LikeOrUnlike&$v=%@",VERSION] parameters:dict cachePolicy:HJCachePolicyIgnoreCache callback:^(id responseObject, NSError *error) {
                [MBProgressHUD hideHUDForView:weakself.view animated:YES];
                if (!error) {
                    if ([[responseObject objectForKey:RESULT_NAME_Success] boolValue]) {
                        if ([weakself.op isEqualToString:@"1"]) {
                            model.IsLike = YES;
                            model.LikeCount = model.LikeCount +1;
                        }else{
                            model.IsLike = NO;
                            model.LikeCount = model.LikeCount -1;
                        }
                        [weakself.tabView reloadData];
                    }else{
                        [MBProgressHUD showErrorOrSuc:[responseObject objectForKey:RESULT_NAME_Message] toView:weakself.view];
                    }
                }else{
                    [MBProgressHUD showErrorOrSuc:@"请求出错" toView:weakself.view];
                }
            }];
        };
        cell.hasReadBlock = ^(NSInteger index, NSString *voiceID){
            NSDictionary *dict= @{@"from":FROM_IOS,
                                  @"busiOrgId":[XGMArchiverTools cacheForKey:BUSIORGID],
                                  @"loginFinger":[XGMArchiverTools cacheForKey:USER_identifierNumber],
                                  @"userId":[XGMArchiverTools cacheForKey:USER_UserId],
                                  @"voiceId":voiceID,
                                  };
            [MBProgressHUD showHUDAddedTo:weakself.view animated:YES];
            [HJNetwork HTTPWithMethod:HJRequestMethodPOST url:[NSString stringWithFormat:@"v30.teecloud.cn/ajax-api.ashx?$c=TeeyunApp&$m=PostVoiceReadStatus&$v=%@",VERSION] parameters:dict cachePolicy:HJCachePolicyIgnoreCache callback:^(id responseObject, NSError *error) {
                [MBProgressHUD hideHUDForView:weakself.view animated:YES];
                if (!error) {
                    if ([[responseObject objectForKey:RESULT_NAME_Success] boolValue]) {
                        for (NSInteger i=0; i<model.VoiceList.count; i++) {
                            GMVoiceListModel *temModel = model.VoiceList[i];
                            if (i == index) {
                                temModel.IsReaded =YES;
                            }
                        }
                        [weakself.tabView reloadData];
                    }else{
                        [MBProgressHUD showErrorOrSuc:[responseObject objectForKey:RESULT_NAME_Message] toView:weakself.view];
                    }
                }else{
                    [MBProgressHUD showErrorOrSuc:@"请求出错" toView:weakself.view];
                }
            }];
        };
        return cell;
    }
}
-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
    return  self.cellArr.count;
}
- (NSInteger)tableView:(nonnull UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    NSString *cellIDStr =self.cellArr[section];
    if ([cellIDStr isEqualToString:@"GMBuyMoneyCell"]) {
        return 0;
    }else if ([cellIDStr isEqualToString:@"GMBuyWebView"]){
        if (kIsEmptyString(self.baseModel.Memo)) {
            //如果没有富文本就不加载cell
            return 0;
        }else{
            return 1;
        }
    }else if ([cellIDStr isEqualToString:@"GMBuyKnowCell"]){
        if (self.baseModel.isopen) {
            return self.baseModel.Dirs.count;
        }else{
            return 0;
        }
    }else{
        return self.baseModel.Remarks.count;
    }
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    NSString *cellIDStr =self.cellArr[indexPath.section];
    if ([cellIDStr isEqualToString:@"GMBuyMoneyCell"]) {
        return 0;
    }else if ([cellIDStr isEqualToString:@"GMBuyWebView"]){
        if (kIsEmptyString(self.baseModel.Memo)) {
            //如果没有富文本就不加载cell
            return 0;
        }else{
            return self.webViewHeight;
        }
    }else if ([cellIDStr isEqualToString:@"GMBuyKnowCell"]){
        if (self.baseModel.isopen) {
            return 50;
        }else{
            return 0;
        }
    }else{
        GMRemarksModel *model = self.baseModel.Remarks[indexPath.row];
        return model.cellHight;
    }
}
- (UIStatusBarStyle)preferredStatusBarStyle {
    if (self.player.isFullScreen) {
        return UIStatusBarStyleLightContent;
    }
    return UIStatusBarStyleDefault;
}

- (BOOL)prefersStatusBarHidden {
    /// 如果只是支持iOS9+ 那直接return NO即可，这里为了适配iOS8
    return self.player.isStatusBarHidden;
}

- (UIStatusBarAnimation)preferredStatusBarUpdateAnimation {
    return UIStatusBarAnimationSlide;
}

- (BOOL)shouldAutorotate {
    return self.player.shouldAutorotate;
}

- (UIInterfaceOrientationMask)supportedInterfaceOrientations {
    if (self.player.isFullScreen) {
        return UIInterfaceOrientationMaskLandscape;
    }
    return UIInterfaceOrientationMaskPortrait;
}
- (IBAction)commentBtnClick:(id)sender {
    GMPopComentVC *conment = [[GMPopComentVC alloc] init];
    conment.resId = self.resId;
    [self.navigationController presentSemiViewController:conment withOptions:@{
                                                                               KNSemiModalOptionKeys.pushParentBack    : @(NO),
                                                                               KNSemiModalOptionKeys.animationDuration : @(0.5),
                                                                               KNSemiModalOptionKeys.shadowOpacity     : @(0.3)
                                                                               }];
}
/**收藏*/
-(void)colectBtnClcik{
    NSDictionary *dict= @{@"from":FROM_IOS,
                          @"busiOrgId":[XGMArchiverTools cacheForKey:BUSIORGID],
                          @"loginFinger":[XGMArchiverTools cacheForKey:USER_identifierNumber],
                          @"userId":[XGMArchiverTools cacheForKey:USER_UserId],
                          @"resId":self.resId,
                          @"type":self.type,
                          };
    [MBProgressHUD showHUDAddedTo:self.view animated:YES];
    [HJNetwork HTTPWithMethod:HJRequestMethodPOST url:[NSString stringWithFormat:@"ajax-api.ashx?$c=TeeyunApp&$m=UnOrCollectRes&$v=%@",VERSION] parameters:dict cachePolicy:HJCachePolicyIgnoreCache callback:^(id responseObject, NSError *error) {
        [MBProgressHUD hideHUDForView:self.view animated:YES];
        if (!error) {
            if ([[responseObject objectForKey:RESULT_NAME_Success] boolValue]) {
                if ([self.type isEqualToNumber:@(1)]) {
                    self.colectBtn.selected = YES;
                    self.type = @(2);
                }else{
                   self.colectBtn.selected = NO;
                    self.type = @(1);
                }
            }else{
                [MBProgressHUD showErrorOrSuc:[responseObject objectForKey:RESULT_NAME_Message] toView:self.view];
            }
        }else{
            [MBProgressHUD showErrorOrSuc:@"请求出错" toView:self.view];
        }
    }];
}
/**分享*/
- (void)shareBtnClick{
    XZShareController *shareVC = [[XZShareController alloc] init];
    shareVC.resId = self.resId;
    [self.navigationController presentSemiViewController:shareVC withOptions:@{
                                                                               KNSemiModalOptionKeys.pushParentBack    : @(NO),
                                                                               KNSemiModalOptionKeys.animationDuration : @(0.6),
                                                                               KNSemiModalOptionKeys.shadowOpacity     : @(0.3)
                                                                               }];
}
- (void)dealloc{
    XZLog(@"%s",__FUNCTION__);
    [self.webView.scrollView removeObserver:self forKeyPath:@"contentSize"];
    /**移除通知*/
    [[NSNotificationCenter defaultCenter] removeObserver:self];
}
@end
